package com.jdyfy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jdyfy.entity.Publicity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface PublicityMapper extends BaseMapper<Publicity> {

    List<Publicity> getPublicitysByProjectNumbers(@Param("projectNumbers") List<String> projectNumbers);

    @Delete("delete from publicitys where publicity_name = #{publicityName}")
    boolean removeByName(String publicityName);

    //公示到期后一个小时，修改公示状态为0
    @Update("UPDATE publicitys SET status = 0 WHERE STR_TO_DATE(CONCAT(DATE(publicity_end_time), ' 23:59:59'), '%Y-%m-%d %H:%i:%s') < DATE_ADD(NOW(), INTERVAL 1 HOUR) AND status != 0")
    void updateExpiredPublicity();

    List<String> getExpiredProjectNames();

    @Delete("DELETE from publicitys where publicity_name like concat('%',#{projectName},'%')")
    void deleteByName(String projectName);

    void updateProjectDealer();
}
